package com.ssy.jt808.protocol.t808;

import com.ssy.jt808.protocol.basics.JTMessage;
import com.ssy.jt808.protocol.commons.JT808;
import com.ssy.jt808.protocol.commons.transform.ParameterConverter;
import io.github.yezhihao.protostar.annotation.Field;
import io.github.yezhihao.protostar.annotation.Message;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author yezhihao
 * https://gitee.com/yezhihao/jt808-server
 */
@Message(JT808.设置终端参数)
public class T8103 extends JTMessage{

  @Field(length=1, desc="参数总数")
  private int                 total;
  @Field(desc="参数项列表", converter=ParameterConverter.class)
  private Map<Integer,Object> parameters;

  public T8103(){
  }

  public T8103( Map<Integer,Object> parameters ){
        this.parameters = parameters;
        this.total = parameters.size();
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public Map<Integer, Object> getParameters() {
        return parameters;
    }

    public void setParameters(Map<Integer, Object> parameters) {
        this.parameters = parameters;
        this.total = parameters.size();
    }

    public T8103 addParameter(Integer key, Object value) {
        if (parameters == null){
            parameters = new TreeMap();
        }
        parameters.put(key, value);
        total = parameters.size();
        return this;
    }
}